package com.vegas.netspider.apps.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.vegas.netspider.dto.SportNote;

public class NoteParser implements WebParser<List<SportNote>>{

	private Pattern pattern = Pattern.compile("<tr\\s*?class=\"b_rig\"\\s*?style=\"display:\\s*?block\">\\s*?<td width=\"40\"\\s*?align=\"center\">(\\d{1,2})</td>\\s*?<td width=\"70\"\\s*?align=\"center\"\\s*?id=\"test\">(.*?)</td>\\s*?<td\\s*?class=\"news\">(.*?)</td>\\s*?</tr>");
	@Override
	public List<SportNote> parse(String res) {
		Matcher m = pattern.matcher(res);
		
		List<SportNote> list = new ArrayList<SportNote>();
		while(m.find()){
			String o = m.group(1);
			String d = m.group(2);
			String c = m.group(3);
			SportNote sn = new SportNote();
			sn.setContent(c);
			sn.setOrder(o+"-"+d);
			list.add(sn);
		}
		return list;
	}

}
